function JxIndex(){
	this.form=this.InitForm();
	this.layer=this.Initlayui();
	this.InitGrid();
}

JxIndex.prototype.InitForm=function(){
	var form;
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       form.on('select(groupid)', function (data) { 
    	   vJxIndex.searchlist();
       });
      
       
	   form.render();
	});  
	return form;
}

JxIndex.prototype.Initlayui=function(){
	var layer;
	layui.use('layer', function(){
		layer = layui.layer;
	})
	return layer;
}
JxIndex.prototype.searchlist = function () {
    this.grid.setOptions({
        newPage: 1, parms: {
            Method: "",
            groupid: $("#groupid").val()
        }
    });
    this.grid.loadData();
}

JxIndex.prototype.InitGrid=function (){
	var _this = this;
    window.liger.remove("list");
    if (_this.grid == null) {
        _this.grid = $("#list").ligerGrid({
            columns: [
                      //{ display: '序号', width: 80, name: 'rowNum' },
                     { display: '内容', width:250, align:'left',name: 'uasscontent',id:"uasscontent",render: function (rowdata, rowindex, value){
                    	 if(rowdata.uasscontent==null){
                    		 return rowdata.uassingredients;
                    	 }
                    	 else{
                    		 return rowdata.uasscontent;
                    	 }
                     }},
                     { display: '分值', width: 100, name: 'score' },
                     { display: '所属单位', width: 200, name: 'orgname' },
                     { display: '组别', width: 100, name: 'groupname' },
                     
                     { display: '评价标准', width: 200, name: 'evaluationstandard',render: function (rowdata, rowindex, value) {
                    	 
//                    	 if(rowdata.evaluationstandard!=null&&rowdata.evaluationstandard!=''&&rowdata.evaluationstandard.length>10){
//                    		 var text=rowdata.evaluationstandard.substr(0,10)+"...";
//                    		 html+='<div title="双击查看详情"  ondblclick="vJxIndex.tabletips(\''+rowdata.evaluationstandard+'\',this)">'+text+'</div>';
//                    		 return html;
//                    	 }
                    	 if(rowdata.evaluationstandard!=''&&rowdata.evaluationstandard!=null){
                    		 var html='<div style="heightt:100px;word-wrap:break-word; word-break:break-all;height:auto">'+rowdata.evaluationstandard+'</div>';
                        	 return html;
                    	 }
                    	 
                     } },
                     { display: '添加时间', width: 180, name: 'createtime' },
                     {display: '操作', width: 100, name: 'userid', render: function (rowdata, rowindex, value) {
                    	 var html=' <img class="btn-img" style="vertical-align:middle" src="'+ctxStatic+'/images/index/btn_edit.png" onclick="vJxIndex.openadd('+rowdata.assindexid+')"  alt="编辑" title="编辑">';
                     	html+='<img class="btn-img" style="vertical-align:middle" src="'+ctxStatic+'/images/index/btn_delete.png" onclick="vJxIndex.deleteentity('+rowdata.assindexid+','+rowdata.parentid+')"  alt="删除" title="删除">';
                     	return html;
                     }}
            ],
            pageSize: 200,
            url: "get_index_list" + '?time=' + new Date().getTime(),
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {
                Method: "",
                groupid: $("#groupid").val()
            },
            sortOrder: null,
            sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '100%',
            heightDiff: -20,
            rowHeight:28,
            onSuccess: function (rowdata, rowindex) { if (rowdata.status > 0) { alert(rowdata.msg) } },
            onAfterShowData:function(){
            	_this.grid.collapseAll();
            },
            alternatingRow: true,
            border: 0,
            //usePager:false,
            tree:{
            	columnId:"uasscontent",
            	idField:"assindexid",
            	parentIDField:"parentid"
            	
            }
        })
    }
}

JxIndex.prototype.tabletips=function(text,obj){
	this.layer.tips(text, obj, {
		  tips: [4, '#78BA32']
	});
}

JxIndex.prototype.openadd=function(assindexid){
	  top.mylayui.open({
	         type: 2,
	         title: '指标添加',
	         shadeClose: true,
	         shade: 0.5,
	         area: ['600px', '430px'],
	         content: 'usualass/index_edit?assindexid='+assindexid
	       }); 
	  var iframeele=top.$(".layui-layer-content").find('iframe');
		iframeele.css({"height":$(iframeele).height()-10});
}

JxIndex.prototype.deleteentity=function(assindexid,parentid){
	 top.mylayui.confirm('确定要删除吗？',{icon: 0}, function(index){
   	 top.mylayui.close(index);
	
	$.ajax({
		type:"POST",
		url:"delete_index",
		data:{assindexid:assindexid,parentid:parentid},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				top.mylayui.msg(data.msg, {icon: 1});
				//vOrg.searchtable();
				document.location.reload();
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
		},
		complete:function(XHR){
			
		},
		error:function(){
			
		}
	});
	 })
}

JxIndex.prototype.addresult=function(result,msg){
	if(result>0){
		top.mylayui.msg('操作成功', {icon: 1});
		top.mylayui.closeAll('iframe');
		//vUser.searchtable();
		document.location.reload();
	}
	else{
		if(msg){
			top.mylayui.msg(msg, {icon: 0});
		}else{
			top.mylayui.msg('操作失败', {icon: 0});
		}
	}
}

var vJxIndex=null;
$(function(){
	vJxIndex=new JxIndex();
})